$(function() {
	$("#submit1").click(function(e) {
		e.preventDefault();
		var url = "http://ittalentsapi.bashibozuk.eu/users/register?X-GameID=102";
		var myData = {};
			
		myData.email = $("#email").val();
		myData.username = $("#username").val();
		myData.password = $("#password").val();
		myData.password_repeat = $("#passwordR").val();
			
		if(myData.email == "" || myData.username == "" || myData.password == "" || myData.password_repeat == "") {
			alert("Please fill all fields...!!!!!!");
		} else if(!(myData.password).match(myData.password_repeat)) {
			alert("Your passwords don't match. Try again?");
		} else {
			$.ajax({
				url: url,
				type: "POST",
				data: myData,
				success: function(data){
					if (data.errors) {
						$('.errors').html('');
						for(i in data.errors) {
							$('#errors_' + i).html(data.errors[i].join('<br>'));
                                                        $('#error').html("Error Invalid username or e-mail");
						}
					} else {
						$('.errors').html('');
						$('#errors').html('You have succesfully register!');
						
					}
				}
			});
		}
	});
});
